<!--
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2025-02-16 18:49:06
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2025-06-27 22:35:14
 * @FilePath: \ruoyi-ui\src\App.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script>
export default  {
  name:  'App',
  data() {
    return {};
  },
  mounted() {
    const isMobile = window.matchMedia("(max-width: 768px)").matches;
    if (isMobile) {
      const body = document.getElementById("app");
      body.style.width = "100%";
      body.style.height = "auto";
      body.style.left = "0";
    } else {
      this.setScale();
      window.addEventListener("resize", this.debounce(this.setScale));
    }
  },
  methods: {
    setScale() {
      const value = this.getScale();
      const body = document.getElementById("app");
      body.style.width = "1920px";
      body.style.height = "928px";
      body.style.position = "relative";
      body.style.transition = "all 0.3s linear";
      body.style.transformOrigin = "0 0";
      body.style.transform =
        "scale(" + value[0] + "," + value[1] + ") translate(-50%, 0)";
      body.style.left = "50%";
    },
    // 计算缩放比例
    getScale() {
      const width = 1920;
      const height = 928;
      const ww = window.innerWidth / width;
      const wh = window.innerHeight / height;
      return [ww, wh];
    },
    debounce(fn, delay) {
      const delays = delay || 500;
      let timer;
      return function () {
        const th = this;
        const args = arguments;
        if (timer) {
          clearTimeout(timer);
        }
        timer = setTimeout(function () {
          timer = null;
          fn.apply(th, args);
        }, delays);
      };
    },
  },
}

</script>
